#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include <stdio.h>
#include "singleton.h"
#include "random.h"

#ifdef WIN32
#include <objbase.h> 
#else
#include <uuid/uuid.h>
typedef struct _GUID {
    unsigned long  Data1;
    unsigned short Data2;
    unsigned short Data3;
    unsigned char  Data4[8];
} GUID;
#endif // WIN32

class KGUID : public AutoSingleton<KGUID> 
{
    friend class AutoSingleton<KGUID>;
public:

    static bool CreateGuid(GUID& guid) 
	{
#ifdef WIN32
        if (::CoCreateGuid(&guid) == S_OK) {
            return true;
        }
        return false;
#else
        uuid_generate(reinterpret_cast<unsigned char *>(&guid));
        return true;
#endif
    }

    static bool CreateGuid(char strGuid[64]) 
	{
        bool ret = false;
        GUID guid;
        ret = CreateGuid(guid);
        if (ret) 
		{
            snprintf(strGuid, 64,
                  "{%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}",
                  (unsigned int)guid.Data1,
                  guid.Data2,
                  guid.Data3,
                  guid.Data4[0], guid.Data4[1],
                  guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5],
                  guid.Data4[6], guid.Data4[7]
                );
        }
        return ret;
    }

protected:
    KGUID() 
	{
       // CoInitialize(NULL);
    }

    ~KGUID() 
	{
       // CoUninitialize();
    }
};
